package com.coder4j.controller;

import com.coder4j.service.STaskFlowDetailService;
import com.coder4j.starter.mybatis.BasePage;
import com.coder4j.starter.web.R;
import com.coder4j.vo.STaskFlowDetailQuery;
import com.coder4j.vo.STaskFlowDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/**
 * 任务流程详情
 * @author keller
 * @date 2025-03-18 16:22:26
 */
@Slf4j
@RestController
@RequestMapping("/sTaskFlowDetail")
public class STaskFlowDetailController {
    @Resource
    private STaskFlowDetailService service;

    @Resource
    private HttpServletResponse response;

    /**
     * 按ID查询任务流程详情
     * @param id STaskFlowDetail.id
     * @return 任务流程详情对象
     */
    @GetMapping("/getById")
    public R<STaskFlowDetailVO> getById( Integer id){

        return R.success(service.baseGetVOById(id));
    }

    /**
     * 保存任务流程详情
     * 有 id 字段，更新；否则新增
     * @param sTaskFlowDetail STaskFlowDetail对象
     * @return STaskFlowDetail对象
     */
    @PostMapping("/save")
    public R save(@RequestBody STaskFlowDetailVO sTaskFlowDetail){


        service.baseSaveVO(sTaskFlowDetail);
        return R.success();
    }

    /**
     * 查询列表
     * @param query 查询条件
     * @return 数据列表
     */
    @PostMapping("/page")
    public R<BasePage<STaskFlowDetailVO>> getList(@RequestBody STaskFlowDetailQuery query){
        if(query == null){
            query = new STaskFlowDetailQuery();
        }
        return R.success(service.baseQueryVOPage(query));
    }

    /**
     * 删除任务流程详情
     * 如果Entity继承了 BaseSoftDeleteEntity，使用逻辑删除；否则，使用物理删除
     * @param id STaskFlowDetail.id
     * @return 删除的数据
     */
    @PostMapping("/deleteById")
    public R deleteById( Integer id){
        service.baseDeleteById(id);
        return R.success();
    }

    /**
     * 获取任务标签列表
     * @return
     */
    @GetMapping("/getLabelList")
    public R getLabelList(Integer taskFlowId) {
        return R.success(service.getTaskLabelList(taskFlowId));
    }

    @GetMapping("/taskNet")
    public R taskNet(@RequestParam(required = false) Integer id,
                     @RequestParam(required = false) Integer type,
                     @RequestParam(required = false) Integer disPlayId,
                     @RequestParam(required = false) Integer controlId){
        if(type == 2){
            controlId = disPlayId;
        }
        try {
            Object o = service.taskNet(id,type,disPlayId,controlId);
            return R.success(o);
        }catch (Exception e){
            return R.success(new ArrayList<>());
        }


    }

    /**
     * 注意力分配评估 模型 列表展示
     * @return
     */
    @GetMapping("/moduleById")
    public R moduleById(@RequestParam(required = false) Integer taskId,
                        @RequestParam(required = false,defaultValue = "0") Integer disPlayId){
        Object o = service.moduleById(taskId,disPlayId);
        return R.success(o);
    }

    @GetMapping("/moudleTaskNet")
    public R taskNet(@RequestParam(required = false) Integer id,
                     @RequestParam(required = false) Integer disPlayId,
                     @RequestParam(required = false) Integer controlId){
        try {
            Object o = service.moudleTaskNet(id,disPlayId,controlId);
            return R.success(o);
        }catch (Exception e){
            return R.success(new ArrayList<>());
        }

    }

    /**
     * 注意力分配评估 模型 列表展示
     * @return
     */
    @GetMapping("/module2ById")
    public R module2ById(@RequestParam(required = false) Integer taskId,
                        @RequestParam(required = false,defaultValue = "0") Integer disPlayId){
        Object o = service.module2ById(taskId,disPlayId);
        return R.success(o);
    }

    /**
     * 注意力分配评估 模型 列表展示
     * @return
     */
    @GetMapping("/module3ById")
    public R module3ById(@RequestParam(required = false) Integer taskId,
                         @RequestParam(required = false,defaultValue = "0") Integer disPlayId){
        Object o = service.module3ById(taskId,disPlayId);
        return R.success(o);
    }
}
